package com.blank.task18;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class StartSystem {
    public static void runSystem()  {
        //准备一个List集合
        List<Student> studentList = null;
        File f = new File("d:/student/stuList.txt");
        if(f.exists()){
            //如果文件存在则读取
            studentList = ReadFileList.readList();
        }else{
            //如果不存在则创建一个新集合
            studentList = new LinkedList<>();
        }
        Scanner sc = new Scanner(System.in);
        System.out.println("==============学生信息管理系统=================");
        int stuNum;
        int age;
        String name;
        while(true){
            System.out.println("1-增加学生信息\t"+"2-删除学生信息\t"+"3-修改学生信息\t"+
                    "4-查找学生信息\t"+"5-打印所有学生信息\t"+"0-退出系统");
            int point = sc.nextInt();
            switch (point){
                case 1:
                    System.out.println("请输入学生学号");
                    stuNum = sc.nextInt();
                    System.out.println("请输入学生姓名:");
                    name = sc.next();
                    System.out.println("请输入学生年龄:");
                    age = sc.nextInt();
                    addStudent.add(stuNum,name,age,studentList);
                    break;
                case 2:
                    System.out.println("请输入删除学生的学号:");
                    stuNum = sc.nextInt();
                    DelStudent.Delete(stuNum,studentList);
                    break;
                case 3:
                    System.out.println("请输入要修改学生的学号:");
                    stuNum = sc.nextInt();
                    Student student = IndexOfStudent.indexOfStu(stuNum,studentList);
                   if(null == student){
                       System.out.println("系统中无该学生信息");
                       break;
                   }
                    System.out.println("请输出要修改的学号:");
                    stuNum = sc.nextInt();
                    System.out.println("请输入要修改的姓名:");
                    name = sc.next();
                    System.out.println("请输出要修改的年龄:");
                    age = sc.nextInt();
                    SetStudent.set(stuNum,name,age,student);
                    break;
                case 4:
                    System.out.println("请输入要查找学生的学号:");
                    stuNum = sc.nextInt();
                    Student student1 = IndexOfStudent.indexOfStu(stuNum,studentList);
                    if(null == student1){
                        System.out.println("查无该学生信息!!!");
                        break;
                    }
                    System.out.println("学生的相关信息为:"+student1);
                    break;
                case 5:
                   ShowStudent.show(studentList);
                   break;
                case 0:
                    System.out.println("退出系统.....");
                    // 将集合写入文件
                    WriteFileList.writeList(studentList);
                    break;
                default:
                    System.out.println("请再次选择功能！！！");
                    break;

            }
            if(0 == point){
                break;
            }

        }
        sc.close();
    }
}
